// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';
const apiPrefix = '/web';

/** 储能柜组件版本列表 GET /v1/ota/cabinet-component/list */
export async function cabinetComponentControllerGetCabinetComponentList(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.cabinetComponentControllerGetCabinetComponentListParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultPaginationOtaStationComponentVO>(
    `${apiPrefix}/v1/ota/cabinet-component/list`,
    {
      method: 'GET',
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

/** 储能柜升级包列表 GET /v1/ota/cabinet-pkg/list */
export async function cabinetComponentControllerGetCabinetPkgList(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.cabinetComponentControllerGetCabinetPkgListParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultPaginationOtaPkg>(`${apiPrefix}/v1/ota/cabinet-pkg/list`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 上传储能柜升级包 POST /v1/ota/cabinet-pkg/upload */
export async function cabinetComponentControllerUploadPkg(
  body: {
    /** 组件编码 */
    componentCode: string;
    /** 版本号 */
    version: string;
    /** 文件名 */
    otaName: string;
  },
  file?: File,
  options?: { [key: string]: any },
) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      if (typeof item === 'object' && !(item instanceof File)) {
        if (item instanceof Array) {
          item.forEach((f) => formData.append(ele, f || ''));
        } else {
          formData.append(ele, JSON.stringify(item));
        }
      } else {
        formData.append(ele, item);
      }
    }
  });

  return request<API.ApiResultVoid>(`${apiPrefix}/v1/ota/cabinet-pkg/upload`, {
    method: 'POST',
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** 升级设备组件包 GET /v1/ota/cabinet-upgrade/issuance */
export async function cabinetComponentControllerUpgradeIssuance(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.cabinetComponentControllerUpgradeIssuanceParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultVoid>(`${apiPrefix}/v1/ota/cabinet-upgrade/issuance`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 储能柜升级记录列表 GET /v1/ota/cabinet-upgrade/list */
export async function cabinetComponentControllerGetCabinetUpgradeLogList(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.cabinetComponentControllerGetCabinetUpgradeLogListParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultPaginationOtaComponentRecordVO>(
    `${apiPrefix}/v1/ota/cabinet-upgrade/list`,
    {
      method: 'GET',
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

/** 此处后端没有提供注释 GET /v1/ota/pkgurl */
export async function cabinetComponentControllerGetUrl(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.cabinetComponentControllerGetUrlParams,
  options?: { [key: string]: any },
) {
  return request<API.ApiResultString>(`${apiPrefix}/v1/ota/pkgurl`, {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
